//
//  NSMutableAttributedString+CEAttribute.m
//  ContinueEducation
//
//  Created by 迟建国 on 2018/7/23.
//  Copyright © 2018年 CE. All rights reserved.
//

#import "NSMutableAttributedString+CEAttribute.h"

@implementation NSMutableAttributedString (CEAttribute)
- (void)setTextColor:(UIColor *)color font:(UIFont *)font space:(CGFloat)space range:(NSRange)range{
    if (self.length > 0 && color && [color isKindOfClass:[UIColor class]] && [font isKindOfClass:[UIFont class]] && space > 0 && self.length >= NSMaxRange(range) && NSMaxRange(range) > 0) {
        NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
        paraStyle. lineBreakMode = NSLineBreakByCharWrapping;
        paraStyle. alignment = NSTextAlignmentLeft;
        paraStyle. lineSpacing = space; //设置行间距
        
        [self addAttributes:@{NSForegroundColorAttributeName:color,NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle} range:range];
    }
    
}
-(void)setStrColor:(UIColor *)color range:(NSRange)range{
    if (self.length > 0 && color && [color isKindOfClass:[UIColor class]] && self.length >= NSMaxRange(range) && NSMaxRange(range) > 0) {
        [self addAttribute:NSForegroundColorAttributeName value:color range:range];
    }
    
}
-(void)setTextSpace:(CGFloat )space range:(NSRange)range{
    if (self.length > 0 && space > 0 && self.length >= NSMaxRange(range) && NSMaxRange(range) > 0) {
        NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
        paraStyle. lineBreakMode = NSLineBreakByCharWrapping;
        paraStyle. alignment = NSTextAlignmentLeft;
        paraStyle. lineSpacing = space; //设置行间距
        [self addAttribute:NSParagraphStyleAttributeName value:paraStyle range:range];
    }
}
@end
